package com.ocm.tourism.web;

import com.ocm.tourism.core.domain.Business;
import com.ocm.tourism.core.domain.Catalogues;
import com.ocm.tourism.core.domain.CommonItems;
import com.ocm.tourism.core.domain.FileInfo;
import com.ocm.tourism.core.domain.Participant;
import com.ocm.tourism.core.domain.Room;
import com.ocm.tourism.core.service.BusinessService;
import com.ocm.tourism.core.service.CataloguesService;
import com.ocm.tourism.core.service.CommonItemsService;
import com.ocm.tourism.core.service.ParticipantService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;

@Configurable
/**
 * A central place to register application converters and formatters. 
 */
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

   @SuppressWarnings("deprecation")
   @Override
   protected void installFormatters(FormatterRegistry registry) {
      super.installFormatters(registry);
      // Register application converters and formatters
   }

   @Autowired
   BusinessService businessService;

   @Autowired
   CataloguesService cataloguesService;

   @Autowired
   CommonItemsService commonItemsService;

   @Autowired
   ParticipantService participantService;

   public Converter<FileInfo, String> getFileInfoToStringConverter() {
      return new org.springframework.core.convert.converter.Converter<com.ocm.tourism.core.domain.FileInfo, java.lang.String>() {
         public String convert(FileInfo fileInfo) {
            return new StringBuilder().append(fileInfo.getName()).append(' ').append(fileInfo.getAbsolutePath())
                  .toString();
         }
      };
   }

   public Converter<Business, String> getBusinessToStringConverter() {
      return new org.springframework.core.convert.converter.Converter<com.ocm.tourism.core.domain.Business, java.lang.String>() {
         public String convert(Business business) {
            return new StringBuilder().append(business.getName()).append(' ').append(business.getAddress()).append(' ')
                  .append(business.getMobilephone()).append(' ').append(business.getHomephone()).toString();
         }
      };
   }

   public Converter<Long, Business> getIdToBusinessConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.ocm.tourism.core.domain.Business>() {
         public com.ocm.tourism.core.domain.Business convert(java.lang.Long id) {
            return businessService.findBusiness(id);
         }
      };
   }

   public Converter<String, Business> getStringToBusinessConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.String, com.ocm.tourism.core.domain.Business>() {
         public com.ocm.tourism.core.domain.Business convert(String id) {
            return getObject().convert(getObject().convert(id, Long.class), Business.class);
         }
      };
   }

   public Converter<Room, String> getRoomToStringConverter() {
      return new org.springframework.core.convert.converter.Converter<com.ocm.tourism.core.domain.Room, java.lang.String>() {
         public String convert(Room room) {
            return new StringBuilder().append(room.getName()).append(' ').append(room.getTypeRoom()).append(' ')
                  .append(room.getPrice()).append(' ').append(room.getCurrency()).toString();
         }
      };
   }

   public Converter<Long, Room> getIdToRoomConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.ocm.tourism.core.domain.Room>() {
         public com.ocm.tourism.core.domain.Room convert(java.lang.Long id) {
            return businessService.findRoom(id);
         }
      };
   }

   public Converter<String, Room> getStringToRoomConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.String, com.ocm.tourism.core.domain.Room>() {
         public com.ocm.tourism.core.domain.Room convert(String id) {
            return getObject().convert(getObject().convert(id, Long.class), Room.class);
         }
      };
   }

   public Converter<Catalogues, String> getCataloguesToStringConverter() {
      return new org.springframework.core.convert.converter.Converter<com.ocm.tourism.core.domain.Catalogues, java.lang.String>() {
         public String convert(Catalogues catalogues) {
            return new StringBuilder().append(catalogues.getName()).append(' ').append(catalogues.getCataloguesType())
                  .append(' ').append(catalogues.getContent()).append(' ').append(catalogues.getDescription())
                  .toString();
         }
      };
   }

   public Converter<Long, Catalogues> getIdToCataloguesConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.ocm.tourism.core.domain.Catalogues>() {
         public com.ocm.tourism.core.domain.Catalogues convert(java.lang.Long id) {
            return cataloguesService.findCatalogues(id);
         }
      };
   }

   public Converter<String, Catalogues> getStringToCataloguesConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.String, com.ocm.tourism.core.domain.Catalogues>() {
         public com.ocm.tourism.core.domain.Catalogues convert(String id) {
            return getObject().convert(getObject().convert(id, Long.class), Catalogues.class);
         }
      };
   }

   public Converter<CommonItems, String> getCommonItemsToStringConverter() {
      return new org.springframework.core.convert.converter.Converter<com.ocm.tourism.core.domain.CommonItems, java.lang.String>() {
         public String convert(CommonItems commonItems) {
            return new StringBuilder().append(commonItems.getName()).append(' ').append(commonItems.getItemTypes())
                  .toString();
         }
      };
   }

   public Converter<Long, CommonItems> getIdToCommonItemsConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.ocm.tourism.core.domain.CommonItems>() {
         public com.ocm.tourism.core.domain.CommonItems convert(java.lang.Long id) {
            return commonItemsService.findCommonItems(id);
         }
      };
   }

   public Converter<String, CommonItems> getStringToCommonItemsConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.String, com.ocm.tourism.core.domain.CommonItems>() {
         public com.ocm.tourism.core.domain.CommonItems convert(String id) {
            return getObject().convert(getObject().convert(id, Long.class), CommonItems.class);
         }
      };
   }

   public Converter<Participant, String> getParticipantToStringConverter() {
      return new org.springframework.core.convert.converter.Converter<com.ocm.tourism.core.domain.Participant, java.lang.String>() {
         public String convert(Participant participant) {
            return new StringBuilder().append(participant.getUsername()).append(' ').append(participant.getPassword())
                  .append(' ').append(participant.getDisplayName()).append(' ').append(participant.getAddress())
                  .toString();
         }
      };
   }

   public Converter<Long, Participant> getIdToParticipantConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.ocm.tourism.core.domain.Participant>() {
         public com.ocm.tourism.core.domain.Participant convert(java.lang.Long id) {
            return participantService.findParticipant(id);
         }
      };
   }

   public Converter<String, Participant> getStringToParticipantConverter() {
      return new org.springframework.core.convert.converter.Converter<java.lang.String, com.ocm.tourism.core.domain.Participant>() {
         public com.ocm.tourism.core.domain.Participant convert(String id) {
            return getObject().convert(getObject().convert(id, Long.class), Participant.class);
         }
      };
   }

   public void installLabelConverters(FormatterRegistry registry) {
      registry.addConverter(getBusinessToStringConverter());
      registry.addConverter(getIdToBusinessConverter());
      registry.addConverter(getStringToBusinessConverter());
      registry.addConverter(getCataloguesToStringConverter());
      registry.addConverter(getIdToCataloguesConverter());
      registry.addConverter(getStringToCataloguesConverter());
      registry.addConverter(getCommonItemsToStringConverter());
      registry.addConverter(getIdToCommonItemsConverter());
      registry.addConverter(getStringToCommonItemsConverter());
      registry.addConverter(getParticipantToStringConverter());
      registry.addConverter(getIdToParticipantConverter());
      registry.addConverter(getStringToParticipantConverter());
      registry.addConverter(getRoomToStringConverter());
      registry.addConverter(getIdToRoomConverter());
      registry.addConverter(getStringToRoomConverter());
      registry.addConverter(getFileInfoToStringConverter());
   }

   public void afterPropertiesSet() {
      super.afterPropertiesSet();
      installLabelConverters(getObject());
   }
}
